<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />
                </div>

                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-normal addBasicData_btn">添加基础数据</a>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
            </div>
        </form>
    </blockquote>
    <table id="basicDataList" lay-filter="basicDataList"></table>
    <!--操作-->
    <script type="text/html" id="basicDataLostListBar">
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //新闻列表
        var tableIns = table.render({
            elem: '#basicDataList',
            url: 'basicDatas',
            cellMinWidth: 95,
            page: true,//分页
            height: "full-125",
            limit: 5,
            limits: [5, 10, 15, 20, 25],
            id: "basicDataListTable",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},//复选框

                {field: 'basiNo', title: '编号', width: 100, align: "center"},
                {field: 'basiType', title: '类别', width: 250, align: "center"},
                {field: 'basiItem', title: '条目', width: 250, align: "center"},
                {field: 'basiValue', title: '值', width: 250, align: "center"},
                {field: 'basiEditable', title: '是否可编辑', width: 100, align: "center", templet: function (row) {
                  return row.basiEditable==1 ?"可编辑":"不可编辑"
                    }
                },
                {title: '操作',templet: '#basicDataLostListBar', fixed: "right", align: "center"}
            ]]
        });
        //搜索
        $(".search_btn").on("click",function(){
            table.reload("basicDataListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    basiType:$(".searchVal").val()
                }
            })
        });
        //单击添加基础数据
        $(".addBasicData_btn").click(function () {
            var index=layui.layer.open({
                title:"添加基础数据字典",
                type:2,
                content:"toAddBasicData.do",
                success : function(layero, index){
                    // var body = layui.layer.getChildFrame('body', index);
                }
            });
            //全屏打开窗口
            layui.layer.full(index);
            window.sessionStorage.setItem("index",index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layui.layer.full(window.sessionStorage.getItem("index"));
            })
        });

        //选择
        table.on("tool(basicDataList)",function (obj) {
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){
                case 'edit'://编辑页面
                    editBasicData(data);
                    break;
                case 'delete'://删除页面
                    deleteBasicData(data);
                    break;
            }
        });
        //编辑界面
        function editBasicData(data) {
            if(data.basiEditable==1) {
                var index = layui.layer.open({
                    title: "编辑基础数据",
                    type: 2,
                    content: "toEditBasicData.do",
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.contents().find(".basiNo").val(data.basiNo);
                        body.contents().find(".basiType").val(data.basiType);
                        body.contents().find(".basiItem").val(data.basiItem);
                        body.contents().find(".basiValue").val(data.basiValue);
                        if (data.basiEditable == 1) {//1是可编辑
                            body.contents().find("input[type='radio']").eq(0).attr("checked", true);
                        } else if (data.basiEditable == 0) {
                            body.contents().find("input[type='radio']").eq(1).attr("checked", true);
                        }
                    }
                })
                layui.layer.full(index);//全屏显示
                }else{
                layer.msg("不可编辑")
            }
        }
        //删除函数
        function deleteBasicData(data) {
            $.ajax({
                url:"basicDatas/"+data.basiNo,
                type:"DELETE",
                dataType:"json",
                success:function (res) {
                    if(res.code==2008){
                        layer.msg(res.msg);
                        tableIns.reload();
                    }else{
                        layer.msg(res.msg);
                        tableIns.reload();
                    }
                }
            })
        }

        $(".delAll_btn").click(function () {

            var checkStatus = table.checkStatus('basicDataListTable');
            var data = checkStatus.data;
            var uIds = [];
            if(data.length > 0) {
                for (var i in data) {
                    uIds.push(data[i].basiNo);
                }
                layer.confirm('确定删除选中的用户？', {icon: 3, title: '提示信息'}, function (index) {
                    /*
                    $.get("/sys/deleteBatchUser.html",{ids:uIds},function (res) {
                        tableIns.reload();
                        layer.close(index);
                    });
                    */
                    $.ajax({
                        url:"basicDatas/deleteBatch",
                        type:"GET",
                        data:{basiNos:uIds},
                        dataType:"json",
                        success:function (res) {
                            if(res.code==2008){
                                layer.msg(res.msg);
                                tableIns.reload();
                                layer.close(index);
                            }else{
                                layer.msg(res.msg);
                                tableIns.reload();
                            }
                        }
                    });
                })
            }else{
                layer.msg("请选择需要删除的用户");
            }
        });

    })
</script>
</body>
</html>